﻿//using ET.DBCommon.DAL;
//using ET.DBCommon.Enum;
//using ET.DBCommon.Model;
using ET_DbCommon.Enum;
using ET_DbCommon.Model;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ET.ScoreTeacherClient.Views
{
    /// <summary>
    /// StepSequenceDiagramView.xaml 的交互逻辑
    /// </summary>
    public partial class StepSequenceDiagramView : Window
    {
        /// <summary>
        /// 时序图窗体 add by zzg
        /// </summary>
        /// <param name="ExamresultsStepID"></param>

        

        public StepSequenceDiagramView(int ExamresultsStepID,string name)
        {
            InitializeComponent();
            this.ExamresultsStepID = ExamresultsStepID;
            GenerateName = name + "_" + ExamresultsStepID;
        }
        public List<DeviceModel> MyStationList { get; set; } = MainWindowNew.DeviceList[(int)DeviceTypeEnum.车站];
        //图片名称
        string GenerateName;
        int ExamresultsStepID { get; set; }
        private int QuestionID { get; set; }
        public string[] StopsRunningTrain { get; set; }
        //有说话的地方了
        double TimeH = 30;
        //说一句话的高度
        double QuantityH = 35;
        //字体高度
        double FontH = 25;
        //边距距离
        double Magin = 10;
        //上边距距离
        double MaginT = 30;
        //对象控件宽度
        double objectW = 30;
        //左边距距离
        double MaginL = 60;
        //根据数据计算行调的长度
        double DiaoDuH = 0;
        private SolidColorBrush NonLineBrush = Brushes.Goldenrod;
        private SolidColorBrush SolidLineBrush = new SolidColorBrush(Color.FromRgb(0, 204, 0));
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        private void DockPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();

        }
        private void Label_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
        }
        private void WindowMin_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void WindowClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void WindowMax_Click(object sender, RoutedEventArgs e)
        {

        }
        private void Generate_Click(object sender, RoutedEventArgs e)
        {
            string path = GetOpenFilesPath();
            if (path == "")
                return;
            path += @"\"+ GenerateName+".png";
            ExportToPng(path);
        }
        /// <summary>
        /// 获取要保存文件名称（含完整路径）
        /// </summary>
        /// <returns></returns>
        private string GetOpenFilesPath()
        {
            string filePath = null;
            System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
            System.Windows.Forms.DialogResult result = dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.Cancel)
                return filePath;
            filePath = dialog.SelectedPath.Trim();
            return filePath;
        }
        /// <summary>
        /// Canvas转换成图片
        /// </summary>
        /// <param name="path">保存的路径</param>
        /// <param name="surface"> 控件名称</param>
        public void ExportToPng(string path)
        {
            try
            {
                if (path == null) return;

                Transform transform = diagramCanvas.LayoutTransform;
                diagramCanvas.LayoutTransform = null;

                Size size = new Size(diagramCanvas.Width, diagramCanvas.Height);
                diagramCanvas.Measure(size);
                diagramCanvas.Arrange(new Rect(size));

                RenderTargetBitmap renderBitmap =
                new RenderTargetBitmap(
                (int)size.Width,
                (int)size.Height,
                96d,
                96d,
                PixelFormats.Pbgra32);
                renderBitmap.Render(diagramCanvas);

                using (FileStream outStream = new FileStream(path, FileMode.Create))
                {
                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
                    encoder.Save(outStream);
                }
                diagramCanvas.LayoutTransform = transform;
                //MessageBox.Show("图片已生成");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }

    
}
